﻿using System;
using FluentValidation;
using Micrhard.FMCG.Server.Models;
using Micrhard.FMCG.Server.Msg;
using Micrhard.FMCG.Server.Interface;
using Microhard.Core;
using FluentValidation.Results;

namespace Micrhard.FMCG.Server.Validator
{
    class IspTemplateAnswerModelValidator : AbstractValidator<IspTemplateAnswerModel>
    {
        public IspTemplateAnswerModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.Comment).Length(1, 50).WithMessage(IspTemplateAnswerMsg.MaxCommentLength).When(r => r.CheckListAnswerID == Guid.Empty);
              
                Custom(u =>
                {
                    IIspTemplateAnswer iclt = IoC.Resolve<IIspTemplateAnswer>();
                    if (iclt.IsNameDuplicate(u))
                    {
                        return new ValidationFailure("Comment", IspTemplateAnswerMsg.DuplicateComment);
                    }
                    return null;
                });
            });
        }
    }
}
